package com.qingcheng.controller.order;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.entity.PageResult;
import com.qingcheng.entity.Result;
import com.qingcheng.pojo.order.Order;
import com.qingcheng.pojo.order.OrderAndOrderItem;
import com.qingcheng.pojo.order.OrderItem;
import com.qingcheng.service.order.OrderService;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Reference
    private OrderService orderService;

    /**
     * 合并订单
     * @param orderId1
     * @param orderId2
     * @return
     */
    @GetMapping("/merge")
    public Result merge(String orderId1, String orderId2){
        orderService.merge(orderId1, orderId2);
        return new Result();
    }

    /**
     * @param orderItems 订单明细拆分对象
     * @return
     */
    @PostMapping("/spilt")
    public Result splitOrderItem(@RequestBody List<OrderItem> orderItems) {
        orderService.splitOrderItem(orderItems);
        return new Result();
    }

    /**
     * 批量修改订单状态、发货状态、发货时间。
     * @param orders
     */
    @PostMapping("/batchSend")
    public Result batchSend(@RequestBody List<Order> orders) {
        orderService.batchSend(orders);
        return new Result();
    }

    /**
     * 返回订单详情与订单明细
     *
     * @param id
     * @return
     */
    @GetMapping("/findOrderResultById")
    public OrderAndOrderItem findOrderResultById(String id) {
        return orderService.findOrderResultById(id);
    }

    /**
     * 根据订单ID数据查询订单集合
     *
     * @param searchMap
     * @return
     */
    @PostMapping("/findOrderListByIds")
    public List<Order> findOrderListByIds(@RequestBody Map searchMap) {
        return orderService.findOrderListByIds(searchMap);
    }

    @GetMapping("/findAll")
    public List<Order> findAll() {
        return orderService.findAll();
    }

    @GetMapping("/findPage")
    public PageResult<Order> findPage(int page, int size) {
        return orderService.findPage(page, size);
    }

    @PostMapping("/findList")
    public List<Order> findList(@RequestBody Map<String, Object> searchMap) {
        return orderService.findList(searchMap);
    }

    @PostMapping("/findPage")
    public PageResult<Order> findPage(@RequestBody Map<String, Object> searchMap, int page, int size) {
        return orderService.findPage(searchMap, page, size);
    }

    @GetMapping("/findById")
    public Order findById(String id) {
        return orderService.findById(id);
    }


    @PostMapping("/add")
    public Result add(@RequestBody Order order) {
        orderService.add(order);
        return new Result();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Order order) {
        orderService.update(order);
        return new Result();
    }

    @GetMapping("/delete")
    public Result delete(String id) {
        orderService.delete(id);
        return new Result();
    }

}
